#!/usr/bin/env python
# -*- encoding: utf-8 -*-

import os
os.system("/var/www/bakuden")
os.system("/home/bakuden/.pyenv/versions/app/lib/site-packages")

import MySQLdb

db_properties = {
                 'DB_SLAVE_HOST':'192.168.10.237',
                 'DB_NAME':'bakuden',
                 'DB_USER':'mcadmin',
                 'DB_PASS':'mcadmin',
                 }

# 获取数据库连接
def get_db_slave():
    try:
        conn = MySQLdb.connect(
                     charset='utf8', init_command='SET NAMES UTF8',
                     host=db_properties['DB_SLAVE_HOST'],
                     db=db_properties['DB_NAME'], user=db_properties['DB_USER'], passwd=db_properties['DB_PASS'])
        conn.cursorclass = MySQLdb.cursors.DictCursor
    except Exception as e:
        print e.message
        return None
    return conn

sql = '''
SELECT  team_id, lv, (SELECT MAX(lv) FROM `user`) max_lv FROM `user` u WHERE u.id = 221856523;
'''

if __name__ == "__main__":
    connection = get_db_slave()
    cur = connection.cursor()
     
    count = cur.execute(sql)
    res = cur.fetchall()
    
    print '-------------',res
    cur.close()
    connection.commit()
    connection.close()
    
